//前台列表编辑框处理
function  check_info(w_type, id, check_span_id, td_check_id, length, type) {
	
	value = ($('#'+check_span_id).html());
	value = value.replace(/"/g, '&quot;');
	$("#"+check_span_id).remove();
	$("#"+td_check_id).html('<input type="text" id="'+check_span_id+'"  value="'+value+'"   style="width:'+length+'px" />');
	$("#"+check_span_id).focus();
	
	$("#"+check_span_id).blur( function () {   
	
		var check_value = $('#'+check_span_id).val();		
		if ( type == 'p_page_click' || type == 'sort'  || type=='ar_count') {
			check_value = parseInt(check_value);
		}	
		
		var str ="<span   id='"+check_span_id+"' >"+check_value+"</span>";
		
		$("#"+td_check_id).html("");
		$("#"+td_check_id).html(str);
		
		$("#"+check_span_id).mouseout( function () { check_css(check_span_id,0); }); 
		$("#"+check_span_id).mouseover( function () { check_css(check_span_id,1); }); 
		
		$("#"+check_span_id).click( function () { check_info(w_type,id,check_span_id,td_check_id,length,type); }); 
		
		if ( type == 'position_name' ) {
			$.get("/wondershare/ad_position.php?action=ajaxAdPostion", { type:'update_position_name', position_id: id, position_name:check_value, w_type: w_type },
			function(data){
				alert(data);
			});  
		}
	});
}

function  check_css(element_id, type) {
	
	if (type == 1) {
		$("#"+element_id).css({  "background": "blue","color": "#ff0011"}); 
	} else {
		$("#"+element_id).css({ "background": "","color":""}); 
	}

}

//删除广告或者广告位
function  delete_ad(id, type, act_type) {

	var str = "";
	var falge = false;
	if (type == 'list') {//代表为多选
		
		if (!confirm('您确定要删除选中的广告记录吗？')) {
			
			$('input[name="ID[]"]').each(function () {
				$(this).attr('checked',false);
			});
			return false;
		}
		
		$('input[name="ID[]"]').each(function () 
		{
			if ($(this).attr('checked'))  {
				
				falge = true;
				str += $(this).val() + ",";
				$("#tr_"+$(this).val()).remove();
				$('#total').html(parseInt($('#total').html())-1) ;
			}
		});
		
		if (!falge) {
			alert('你没有选择任何选项！');   
		}
	} else {
		str = id+','; 
		$("#tr_"+id).remove();
		$('#total').html(parseInt($('#total').html())-1) ;
	}
	
	if (act_type == 'ad') {//代表为广告删除
	
		$.get("/wondershare/ad.php?action=ajaxAd", {type: 'del_ad', ad_id_str: str },
		function(data){}); 
	} else if (act_type == 'ad_position') {//代表为广告位删除
		$.get("/wondershare/ad_position.php?action=ajaxAdPostion", {type:'del_ad_postion', position_id_str: str },
		function(data){
		
		}); 
	}

}

//根据网站类型得到广告位列表
function get_ad_position_list(type) {
	
	var w_type = $("#w_type").val();
	var new_group_position = $("#new_group_position").val();
	var ad_id = $("#ad_id").val();
	var old_group_position = $("#old_group_position").val();
	
	if ( type == 'delivery_list' ) {
		jIframe('', '所有广告位置列表', {
		width: 830,
		height: 355,
		src: 
		'./ad.php?action=adPositionList&w_type='+w_type+'&new_group_position='+new_group_position+'&old_group_position='+old_group_position+'&ad_id='+ad_id,
		ID: 'all_ad_position',
		box_btn:true,
		callback:get_check_ad_position
		});
	}

}

//确定

function get_check_ad_position() {
	
	var new_group_position = document.getElementById("all_ad_position").contentWindow.get_checked_value();

	var old_group_position = document.getElementById("all_ad_position").contentWindow.get_old_group_position();
	var ad_id = document.getElementById("all_ad_position").contentWindow.get_ad_id();
	$.get("/wondershare/ad.php?action=adPositionList", {type: 'is_exist_position',new_group_position:new_group_position,
	old_group_position:old_group_position,ad_id:ad_id,w_type:$("#w_type").val() },
	function(data){

		if (data['tips'] != '' ) {
			
			if (confirm(data['tips']+'\n\n'+'已关联其他广告，是否替换广告？')) {
				$("#new_group_position").val(data['new_group_position']);
				$("#delivery_content").html(data['ad_position_name_str']);
				jClose();
			}
		 } else {
			$("#new_group_position").val(data['new_group_position']);
			$("#delivery_content").html(data['ad_position_name_str']);
			jClose();
		}
	
	},'json'); 

}


